package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.constant.order.OrderTypeEnum;
import com.ssy.lingxi.common.model.vo.SelectItemVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.comment.request.WaitCommentOrderQueryVO;
import com.ssy.lingxi.member.merchant.model.vo.comment.response.WaitCommentOrderPageVO;
import com.ssy.lingxi.member.merchant.service.web.IMemberOrderCommentService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @menu 交易能力 - 会员订单评价
 * @author yzc
 * @version 2.0.0
 * @date 2021/8/3
 */
@RestController
@RequestMapping("/member/orderComment")
public class MemberOrderCommentController {

    @Resource
    private IMemberOrderCommentService memberOrderCommentService;

    /**
     * 待评价订单 - 订单类型
     * @return 查询结果
     */
    @RequestMapping(value = "/orderType/list", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> listOrderType() {
        List<SelectItemVO> resultList = Stream.of(OrderTypeEnum.values()).map(e -> {
            SelectItemVO selectItemVO = new SelectItemVO();
            selectItemVO.setValue(e.getCode());
            selectItemVO.setName(e.getName());
            return selectItemVO;
        }).collect(Collectors.toList());

        return Wrapper.success(resultList);
    }

    /**
     * 采购会员 - 待评价订单
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/buyer/page", method = RequestMethod.GET)
    public Wrapper<PageData<WaitCommentOrderPageVO>> pageBuyerWaitCommentOrder(@RequestHeader HttpHeaders headers, @Valid WaitCommentOrderQueryVO pageVO) {
        return memberOrderCommentService.pageBuyerWaitCommentOrder(headers, pageVO);
    }

    /**
     * 供应会员 - 待评价订单
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/vendor/page", method = RequestMethod.GET)
    public Wrapper<PageData<WaitCommentOrderPageVO>> pageVendorWaitCommentOrder(@RequestHeader HttpHeaders headers, @Valid WaitCommentOrderQueryVO pageVO) {
        return memberOrderCommentService.pageVendorWaitCommentOrder(headers, pageVO);
    }
}
